// Provides methods for serialization and de-serialization of data in a
// standardized, platform-independent way.
//
// Pickle objects will grow dynamically.

#ifndef BASE_PICKLE_H
#define BASE_PICKLE_H

#include <vector>

#include "base/types.h"

namespace base {

class Pickle {
public:
    // Create a pickle with a default initial size.
    Pickle();

    // Create a pickle with a specified initial size.  Useful if the space
    // requirements are known ahead of time.
    explicit Pickle(int size);

    inline int Size() const { return data_.size(); }

    void WriteBool(bool value);
    bool ReadBool();

    void WriteInt8(int8 value);
    void WriteInt16(int16 value);
    void WriteInt32(int32 value);
    void WriteInt64(int64 value);

    int8 ReadInt8();
    int16 ReadInt16();
    int32 ReadInt32();
    int64 ReadInt64();

    void WriteUInt8(uint8 value);
    void WriteUInt16(uint16 value);
    void WriteUInt32(uint32 value);
    void WriteUInt64(uint64 value);

    uint8 ReadUInt8();
    uint16 ReadUInt16();
    uint32 ReadUInt32();
    uint64 ReadUInt64();

    void WriteFloat(float value);
    float ReadFloat();

    void WriteDouble(double value);
    double ReadDouble();

    void WriteFromBuffer(const void* buffer, int size);
    void ReadIntoBuffer(void* buffer, int size);

private:
    // Basic methods for writing and reading a single value at a time.
    void Write(uint8 value);
    uint8 Read();

    // Our internal storage.  Currently we are using a vector, but we may
    // want to revisit this because a vector may not be perfect for our needs.
    std::vector<uint8> data_;

    // Our current read position in the data.
    int read_index_;

    DISALLOW_COPY_CONSTRUCTORS(Pickle);
};

} // namespace base

#endif // BASE_PICKLE_H
